PACKAGES

These are the packages installed for this model.

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(leaflet)
library(sf)
## Linking to GEOS 3.10.2, GDAL 3.4.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(tigris)
## To enable caching of data, set `options(tigris_use_cache = TRUE)`
## in your R script or .Rprofile.

Data

Calls for Service + Geographical Data

id.calls <- "1gRoL7lZlwm7sreA5F9WbPoH5su4n4iGS"
calls.temp <- read.csv(sprintf("https://docs.google.com/uc?id=%s&export=download", id.calls))

fairfax.roads <- roads("VA", "Fairfax city")
fairfax.city <- county_subdivisions("VA", "Fairfax city")

#Clean Data

calls.temp$date <- as.Date(calls.temp$date)
calls.temp$dow <- weekdays(calls.temp$date)
calls.temp$month <- substr(calls.temp$date, 6, 7)
calls.full <- subset(calls.temp, !is.na(calls.temp$lat))

#Calculations

calls.year <- calls.full %>%
  group_by(year) %>%
  summarise(count = n()) %>%
  mutate(PCT = round(count/sum(count)*100,2))

calls.type <- calls.full %>%
  group_by(type) %>%
  summarise(count = n()) %>%
  mutate(PCT = round(count/sum(count)*100,2))

calls.type <- calls.type[order(-calls.type$count),] # sort in descending order by count
diffs <- diff(calls.type$PCT)
diffs <- c(0, diffs)
calls.type$diff <- diffs

#Filter Data

###Call Type

calls <- subset(calls.full, calls.full$type == 'TRESPASSING' | calls.full$type == 'LARCENY')

Graph 1: Activity by Day of Week

ggplot(subset(calls, calls$year == '2007'), aes(x=lon, y=lat, color = dow)) + 
  geom_point()

Analysis #1

According to this graph analyzing the day of week for trespassing and larceny from 2007 in Fairfax City, there are several hot spot and cold spot locations that can be recognized. Looking at hot spots, we can see Monday, Tuesday, and Friday contain 2 hot spots located in the Northeast and Southwest area; Wednesday, Thursday, and Saturday contain 1 hot spot located in the Northeast area; and Sunday contains 0 hot spots. Looking at cold spots, all of the days contain 2 cold spot areas located in the North and Northwest region of the city. While some areas begin to turn gray and dark blue in the West and lower Southeast region, the location of each hot spot and cold spot seem to be consistent throughout each day of week since 2007. To make future predictions using this information, I predict cold spots will remain located in 2 areas in the North and Northwest region, specifically, within the communities near, or off of, Plantation Parkway such as Blue Coat Drive. Additionally, I predict hot spots will remain closer to the Southwest region near University Drive and Willard Way, and in the Northeast region near Fairfax Blvd and Old Lee Highway.

Graph 2: Activity by Hour of Day

ggplot() + 
  geom_sf(data = fairfax.city) +
  geom_sf(data = fairfax.roads) +
  stat_density2d(aes(x = lon, y = lat, fill = ..level.., alpha = 0.01), 
                 size = 0.001, bins = 5, data = calls, geom = "polygon") + 
  theme_classic() + 
  theme(legend.position = "none") +
  facet_wrap(~ hour, nrow = 4)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The dot-dot notation (`..level..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(level)` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Analysis #2

According to this graph analyzing hour of day for trespassing and larceny from 2007 in Fairfax City, there are several hot spot and cold spot locations to be recognized. Looking at hot spots, we can see between the hours of 12am-7am there are no hot spots, or light blue, areas; there are only dark blue areas within the Northwest and Southwest region. At the hours of 8am, 11am, and 12pm, there is 1 hot spot located in the Northwest region, and at 4pm, there is 1 hot spot location in the Southwest region. Looking at cold spots, between the hours of 1-3am and 5-7am, there are 4 cold spots present in the North, Northwest, East, and Southeast region; and from 4am, 9am-3pm, and 5pm-12am, there are 3 cold spots present in the North, Northwest, and East region; and at 8am, there are 2 cold spot locations in the Northwest and East region. Two specific areas in the southwest and northeast region seem to shift between being the hot spot throughout the day while the cold spots remain consistent. To make future predictions using this information, I predict the hot spot will continue to move back and forth between the southwest, off of Willard Way, and northeast region, near Old Lee Highway and Arlington Blvd; the cold spots will remain in the North, Northwest, and East region, specifically near Old Lee Highway and Arlington Blvd.

Graph 3: Activity by Month of Year

ggplot() + 
  geom_sf(data = fairfax.roads, inherit.aes = FALSE, color = "grey", size = .3, alpha = .5) + 
  geom_point(aes(x = lon, y = lat, color = "blue"), data = calls, alpha = 0.1, size = 1.5) +
  theme_void() + 
  theme(plot.title = element_text(size = 20, hjust=.5), plot.subtitle = element_text(size = 8, hjust=.5, margin=margin(2, 0, 5, 0))) + 
  labs(title = "Fairfax, VA", subtitle = "Trespassing + Larceny") +
  facet_wrap(~ month, nrow = 3)

Analysis #3

According to this graph analyzing month of year for trespassing and larceny from 2007 in Fairfax City, there are several hot spot and cold spot locations to be recognized. Looking at hot spots, we can see in January there are 2 hot spots in the Southwest and Northeast region, in February there are 0 hot spots, from March-October there is 1 hot spot in the Northeast region with 1 month, October’s hot spot, being in the Southwest region, and from November-December there are 0 hot spots. Looking at cold spots, there are 2 consistent cold spots in the North and Northwest region. While analyzing each month, it was recognized that, unlike the analysis on each hour of the day, the hot spot was consistent with being in the North and Northwest region. To make future predictions using this information, I predict the hot spot will continue to remain in the Northeast region, specifically near Arlington Blvd and Old Lee Highway, and will not shift to the Southwest region. Additionally, I predict cold spots will remain in the North, near Plantation Pkwy, and and Northwest region, near Carol and Hill Street.

Graph 4: Interactive Cluster Map

leaflet(calls) %>%
  addProviderTiles("CartoDB.DarkMatter") %>%
  addMarkers(lng = ~lon, lat = ~lat,
             popup = paste(
               "Call Type: ", calls$type, "<br>",
               "Date:", calls$date), 
             clusterOptions = markerClusterOptions()) %>%
  addPolygons(data = fairfax.city)
## Warning: sf layer has inconsistent datum (+proj=longlat +datum=NAD83 +no_defs).
## Need '+proj=longlat +datum=WGS84'
2059
44
721
2196
28
926
833
1549
3688
Leaflet | © OpenStreetMap contributors © CARTO